import PaBaseModel from '../../core/model/PaBaseModel';

function meetingDetailCtrl($scope, $http, ngDialog, paFetchService) {
  'ngInject';
  let id = $state.params.id;

  this.meetingList = {};

  this.profilesToken = {}; // 获取上传文件的token

  this.editable = false;

  // 获取会议详情信息
  this.meetingInit = () => {
    var url = `${SERVER_CONTEXT}/api/securityactivities/securityMeeting/queryById/${id}`;
    $http.get(url)
      .then((resp) => {
        if(resp.statusText == 'OK'){
          this.meetingList = resp.data; // 基本信息
          this.editMeetingList = new PaBaseModel(this.meetingList); // 可编辑基本信息数据
        }              
    });
  }

  // 修改
  this.remark = () => {
    this.editable = true;
  }

  // 保存修改信息
  this.save = () => {

    // 把文件上传返回token传入this.userInfo
    this.editMeetingList.fileIds = [];
    let filesToken = this.profilesToken;
    for(let key in filesToken){
      this.editMeetingList.fileIds.push(filesToken[key]);
    }
    this.editMeetingList.fileIds;
    $http.post(`${SERVER_CONTEXT}/api/securityactivities/securityMeeting/updateSecurityMeeting`,
      this.editMeetingList).
      then((resp) => {
        console.log(resp);
        if(resp.data.success){
          $scope.meetingDetail.editMeetingList.$sync();         
          $state.reload();
        } else {
          layer.alert('错误');
        }
    });
  }

  //重置
  this.cancel = () => {
     this.editMeetingList.$reset();
     this.editable = false;
  }

  // 初始化页面
  this.initPage = () => {
    // 获取会议详情信息
    this.meetingInit();

    // 获得项目部list
    paFetchService
                  .getOrgList()
                  .then((resp) => {
                    this.orgList = resp.data;
                  });
  }

  this.initPage();


}

export default meetingDetailCtrl;